﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace TaskKernel.DTO
{
    public class FileModel
    {
        public Stream Content;
        public string FileName;
        public int Size;
    }

  

    [Serializable]
    public class HistoryModel
    {
        public HistoryModel(DateTime? date, string comment, string login)
        {
            Date = date;
            Comment = comment;
            Login = login;
        }

        public DateTime? Date { protected set; get; }
        public string Comment { protected set; get; }
        public string Login { protected set; get; }
    }

    [Serializable]
    public class UniversalModelDDL : IEquatable<UniversalModelDDL>
    {
        public UniversalModelDDL(Guid id, string name)
        {
            ID = id;
            Name = name;
        }

        public Guid ID { protected set; get; }
        public string Name { protected set; get; }

        #region IEquatable<UniversalModelDDL> Members

        public virtual bool Equals(UniversalModelDDL other)
        {
            return (ID == other.ID);
        }

        #endregion
    }

    [Serializable]
    public class ParticipantsModelDDL : UniversalModelDDL, IEquatable<ParticipantsModelDDL>
    {
        public ParticipantsModelDDL(UniversalModelDDL universalModelDdl, bool isAdded)
            : base(universalModelDdl.ID, universalModelDdl.Name)
        {
            IsAdded = isAdded;
        }

        public bool IsAdded { protected set; get; }

        #region IEquatable<ParticipantsModelDDL> Members

        public virtual bool Equals(ParticipantsModelDDL other)
        {
            return (ID == other.ID);
        }

        #endregion
    }

    [Serializable]
    public class ExecutorsModel
    {
        public ExecutorsModel(string fullname, int count, IList<AbstractTaskList> tasklist)
        {
            FullName = fullname;
            CountTask = count;
            TaskList = tasklist;
        }

        public string FullName { get; protected set; }
        public int CountTask { get; protected set; }
        public IList<AbstractTaskList> TaskList { get; protected set; }

        public ExecutorsModel Sort(string expression, bool sortDirection)
        {
            if (!String.IsNullOrEmpty(expression))
            {
                TaskList = sortDirection
                               ? TaskList.AsQueryable().OrderBy(expression).ToList()
                               : TaskList.AsQueryable().OrderByDescending(expression).ToList();
            }
            return this;
        }

        public ExecutorsModel SortByMany(Queue<AbstractSortField> expressions)
        {
            const int oneElementExpression = 1;
            int count = expressions.Count();
            AbstractSortField field = expressions.Dequeue();
            if (count > oneElementExpression)
            {
                if (field.SortDirectionAsc)
                {
                    TaskList =
                        TaskList.AsQueryable().OrderBy(field.Field).ThenBy(new Queue<AbstractSortField>(expressions)).
                            ToList();
                }
                else
                {
                    TaskList =
                        TaskList.AsQueryable().OrderByDescending(field.Field).ThenBy(
                            new Queue<AbstractSortField>(expressions)).ToList();
                }
            }
            if (count == oneElementExpression)
                Sort(field.Field, field.SortDirectionAsc);
            return this;
        }
    }

    [Serializable]
    public class ImageSet
    {
        public bool Exclamation { get; set; }
        public bool Reminder { get; set; }
        public bool iamParticipant { get; set; }
    }

    [Serializable]
    public class AbstractTaskList
    {
        protected AbstractTaskList(string link, string taskName, string role, DateTime? datecreate,
                                   DateTime? dateLastComment, ImageSet imageLink, string tag)
        {
            TaskName = taskName;
            HyperLink = link;
            Owner = role;
            DateCreate = datecreate;
            ImageLink = imageLink;
            DateLastComment = dateLastComment;
            Tag = tag;
        }

        public ImageSet ImageLink { get; protected set; }
        public string TaskName { get; protected set; }
        public string HyperLink { get; protected set; }
        public string Owner { get; protected set; }
        public DateTime? DateCreate { get; protected set; }
        public DateTime? DateLastComment { get; protected set; }
        public virtual DateTime? DateExpiration { get; protected set; }
        public virtual string Priority { get; protected set; }
        public virtual string Complete { get; protected set; }
        public virtual string Executor { get; protected set; }
        public virtual DateTime? DateClose { get; protected set; }
        public virtual string Department { get; protected set; }
        public virtual string Tag { get; protected set; }
    }

    [Serializable]
    public class TaskListInDepartmentModel : AbstractTaskList
    {
        public TaskListInDepartmentModel(string link, string taskName, string role, DateTime? datecreate,
                                         DateTime? dateexpir, DateTime? dateLastComment, string priority,
                                         string complete, ImageSet imageLink, string tag)
            : base(link, taskName, role, datecreate, dateLastComment, imageLink, tag)
        {
            DateExpiration = dateexpir;
            Priority = priority;
            Complete = complete;
        }

        public override DateTime? DateExpiration { get; protected set; }
        public override string Priority { get; protected set; }
        public override string Complete { get; protected set; }
    }

    [Serializable]
    public class ArchiveTaskListModel : AbstractTaskList
    {
        public ArchiveTaskListModel(string link, string taskName, string role, DateTime? datecreate, DateTime? dateclose,
                                    DateTime? dateLastComment, string role2, string department, ImageSet imageLink,
                                    string tag)
            : base(link, taskName, role, datecreate, dateLastComment, imageLink, tag)
        {
            Executor = role2;
            DateClose = dateclose;
            Department = department;
        }

        public override string Executor { get; protected set; }
        public override DateTime? DateClose { get; protected set; }
        public override string Department { get; protected set; }
    }

    [Serializable]
    public class TaskListForExecutorInAllDepModel : TaskListInDepartmentModel
    {
        public TaskListForExecutorInAllDepModel(string link, string taskName, string role, DateTime? datecreate,
                                                DateTime? dateexpir, DateTime? dateLastComment, string priority,
                                                string complete, string department, ImageSet imageLink, string tag)
            : base(link, taskName, role, datecreate, dateexpir, dateLastComment, priority, complete, imageLink, tag)
        {
            Department = department;
        }

        public override string Department { get; protected set; }
    }

    [Serializable]
    public class AbstractSortField : IEquatable<AbstractSortField>
    {
        private readonly string _field;
        protected bool _selected;
        protected bool _sortDirectionAsc;

        public AbstractSortField(string field, bool sortDirectionAsc)
        {
            _selected = false;
            _field = field;
            _sortDirectionAsc = sortDirectionAsc;
        }

        public string Field
        {
            get { return _field; }
        }

        public bool Selected
        {
            get { return _selected; }
        }

        public bool SortDirectionAsc
        {
            get { return _sortDirectionAsc; }
        }

        #region IEquatable<AbstractSortField> Members

        public bool Equals(AbstractSortField other)
        {
            return _field == other._field;
        }

        #endregion

        public void SetFieldSelected(bool expr)
        {
            _selected = expr;
        }
    }

    [Serializable]
    public class SortingField : AbstractSortField
    {
        private readonly string _description;
        private readonly bool _visible;

        public SortingField(string field, string description, bool visible, bool sortDirectionAsc)
            : base(field, sortDirectionAsc)
        {
            _description = description;
            _visible = visible;
        }

        public bool Visible
        {
            get { return _visible; }
        }

        public string Description
        {
            get { return _description; }
        }

        public void SetSortDirection(bool sortDirectionAsc)
        {
            _sortDirectionAsc = sortDirectionAsc;
        }
    }

    public class Tracker
    {
        public string Title { get; set; }
        public string Initiator { get; set; }
        public string InitiatorMail { get; set; }
        public string Executor { get; set; }
        public string Owner { get; set; }
        public string Participants { get; set; }
        public string Action { get; set; }
        public string Link { get; set; }
        public string TextReminder { get; set; }
        public string Comments { get; set; }
        public string Files { get; set; }
        public string SenderDisplayName { get; set; }
    }
}